package cn.java81.jdbc;

import cn.java81.util.DbUtil;

import java.sql.*;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class StudentFenye {
    //滚动结果集
    public static void main(String[] args) {
        //一页13，第五页 53-65
        //占位符的方案：错误
        String sql = "select * from s_student order by stuno desc limit ?,?";
        Scanner sc=new Scanner(System.in);
        System.out.println("一页多少条：");
        int pageSize=sc.nextInt();
        System.out.println("要查第几页：");
        int pageNo=sc.nextInt();
        int start=(pageNo-1)*pageSize;
        Connection connection = DbUtil.getConnection();
        PreparedStatement st = null;
        ResultSet rs = null;
        try {
            st = connection.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            st.setLong(1,start);
            st.setInt(2,pageSize);
           rs=st.executeQuery();
            while (rs.next()){
                System.out.println("学号："+rs.getLong("stuno"));
               String name=rs.getString("sname");
               String qq=rs.getString("qq");
                //Date enterdate = rs.getDate("enterdate");
                Timestamp enterdate = rs.getTimestamp("enterdate");
                System.out.println(name+","+qq+","+enterdate);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DbUtil.close(rs, st, connection);
        }

    }
}
